package com.wolfware.athsweb.aspects;

import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.ThrowsAdvice;

public class AthswebLogger implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice{

	//private Log log = LogFactory.getLog(getClass());
	private Log log = null;
	
	//@Pointcut("execution(* com.wolfware.athsweb.service.impl.AthsWebBackOfficeServiceImpl.*(..))")
	public void log() {
	}
	
	/*@Around("log()")
    public Object log(ProceedingJoinPoint call) throws Throwable
    {		
        log.info("Entering method [" + call.toShortString() +"]");
        Object point =  call.proceed();
        log.info("Exiting method [" + call.toShortString() + "with return as:" + point);        

        return point;
    }*/

	public void before(Method method, Object[] args, Object target) throws Throwable {
		log = LogFactory.getLog(target.getClass());
		
		log.info("Entering method [" + method.getName() +"]");
		
	}

	public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
		log = LogFactory.getLog(target.getClass());
		
		log.info("Exiting method [" + method.getName() + "with return as:" + returnValue);
	}
	
	public void afterThrowing(Method m, Object[] args, Object target, Throwable ex) { 
		log = LogFactory.getLog(target.getClass());
		
		log.info("Exception in method: "+m.getName()+" Exception is: "+ex.getMessage());	
	}
	
}